package com.huike.web.controller.system;

import com.huike.clues.mapper.SysRoleDeptMapper;
import com.huike.clues.mapper.SysRoleMapper;
import com.huike.clues.service.ISysRoleService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.entity.SysRole;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * @Author: Copyright by jiyuzm
 * @Date: 2023/07/11/15:16
 * @Description: 角色管理类
 */


@Slf4j
@RestController
@Api(tags = "角色管理类")
@RequestMapping("/system/role")
public class SysRoleController extends BaseController {

    @Resource
    private ISysRoleService sysRoleService;

    @Resource
    private SysRoleMapper sysRoleMapper;

    @Resource
    private SysRoleDeptMapper sysRoleDeptMapper;


    @PostMapping
    @ApiOperation("新增角色")
    public AjaxResult newRole(@RequestBody SysRole sysRole){
        sysRoleService.newRole(sysRole);
        return AjaxResult.success();
    }

    @PutMapping
    @ApiOperation("修改角色")
    public AjaxResult<SysRole> modifyRole(@RequestBody SysRole sysRole){
        sysRoleService.modifyRole(sysRole);
        return AjaxResult.success();
    }

    @PutMapping("/changeStatus")
    @ApiOperation("状态修改")
    public AjaxResult changeStatus(@RequestBody SysRole sysRole){
        sysRoleService.changeStatus(sysRole);
        return AjaxResult.success();
    }

    @PutMapping("/dataScope")
    @ApiOperation("修改角色权限")
    public AjaxResult modifyRolePermissions(@RequestBody SysRole sysRole){
        sysRoleService.modifyRolePermissions(sysRole);
        return AjaxResult.success();
    }

    @GetMapping("/export")
    @ApiOperation("")
    public AjaxResult export(SysRole role) {
        List<SysRole> list = sysRoleService.selectRoleList(role);
        ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);
        return util.exportExcel(list, "角色数据");
    }


    @GetMapping("/list")
    @ApiOperation("分页查询角色列表")
    public TableDataInfo listPage(SysRole sysRole){
        startPage();
        List<SysRole> list = sysRoleService.selectRoleList(sysRole);
        return getDataTable(list);
    }


    @GetMapping("/optionselect`")
    @ApiOperation("获取角色选择框列表")
    public AjaxResult optionselect(){
        return AjaxResult.success(sysRoleService.optionselect());
    }


    @DeleteMapping("/{roleIds}")
    @ApiOperation("删除角色")
    public AjaxResult deleteRole(@PathVariable Long[] roleIds){
        int sysRole = sysRoleService.deleteRole(roleIds);
        return AjaxResult.success(sysRole);
    }


    @GetMapping("/{roleId}")
    @ApiOperation("根据角色编号获取详细信息")
    public AjaxResult getDetails(@PathVariable Long roleId){
        SysRole sysRole = sysRoleService.selectRoleByRoleId(roleId);
        return AjaxResult.success(sysRole);
    }












}
